<template lang="pug">
.registration-query-form
  mt-form(v-bind="patientFormProps")
  el-row(
    justify="end"
  )
    mt-button(type="primary",@click="queryBtnClick",icon="Search") 查询
    mt-button(type="primary",@click="resetBtnClick",icon="House") 重置
    mt-button(type="primary",@click="isShowBtnClick",:icon="isShowIcon") {{ !showSpan ? '展开' : '收起' }}
</template>
<script setup lang="ts">

import { type FormItemProps, type FormProps } from "@scmt/common-components";
import { type RegistrationEntity, RegistrationStateEnum } from "@scmt/api-pacs-registration";
import { useApi } from "@scmt/core-api";
//添加 Props属性
const props = defineProps({
  selectRegistration: Object,
});
const $api = useApi();
const editingObj = ref<{} | RegistrationEntity>({});
const showSpan = ref(true);
//是否展示
const isShowIcon = ref("ArrowDown");
//定义事件
const emit = defineEmits(['handleQuery']);
const RegistrationStateOptions = [
  { label: "待检查", value: RegistrationStateEnum.Order },
  { label: "待诊断", value: RegistrationStateEnum.ToBeDiagnosed },
  { label: "诊断中", value: RegistrationStateEnum.Progress },
  { label: "待审核", value: RegistrationStateEnum.Diagnosed },
];
const patientFormProps = computed<FormProps>(() => {
  const formItems: FormItemProps[] = [
    // {
    //   prop: "patientId",
    //   label: "病人编号",
    //   required: false,
    //   visible: true
    // },
    {
      prop: "inspectionNumber",
      label: "检查编号",
      required: false,
      visible: true
    },
    {
      prop: "outpatientNumber",
      label: "业务编号",
      required: false,
      visible: true
    },

    {
      prop: "name",
      label: "姓名",
      required: false,
      visible: true
    },

    {
      prop: "idCard",
      label: "身份证号",
      required: false,
      visible: true
    },
    {
      prop: "patientType",
      label: "业务来源",
      required: false,
      visible: true,
      as: "select",
      options: {
        loadMethod: () => $api.dict.item.listAsOptions("patient-type"),
      },
    },
    {
      prop: "registrationState",
      label: "检查状态",
      as: "select",
      visible: showSpan.value,
      options: {
        options: RegistrationStateOptions,
      },
    },
    // {
    //   prop: "admissionNumber",
    //   label: "住院号",
    //   required: false,
    //   visible: showSpan.value
    // },
    // {
    //   prop: "outpatientNumber",
    //   label: "门诊号",
    //   required: false,
    //   visible: showSpan.value
    // },
    // {
    //   prop: "ward",
    //   label: "病区",
    //   required: false,
    //   as: "select",
    //   visible: showSpan.value
    // },
    // {
    //   prop: "bedNumber",
    //   label: "床位号",
    //   required: false,
    //   as: "select",
    //   visible: showSpan.value
    // },
    {
      prop: "applyingOfficeId",
      label: "申请科室",
      required: false,
      as: "select",
      visible: showSpan.value,
      options: {
        render: "office-table",
        loadMethod: $api.upms.org.listAsOptions,
      },
    },
    {
      prop: "applyingDoctor",
      label: "申请医生",
      required: false,
      as: "select",
      visible: showSpan.value,
      options: {
        render: "doctor-table",
        //@ts-ignore
        loadMethod: () => $api.user.listDoctorAsOptions({ officeId: editingObj.value?.applyingOfficeId }),
      }
    },
    // {
    //   prop: "applicationRemarks",
    //   label: "申请备注",
    //   required: false,
    //   visible: showSpan.value
    // },
    // {
    //   prop: "medicalHistoryData",
    //   label: "病史资料",
    //   required: false,
    //   visible: showSpan.value
    // },
    // {
    //   prop: "clinicalDiagnosis",
    //   label: "临床诊断",
    //   required: false,
    //   visible: showSpan.value
    // },

    {
      prop: "urgent",
      label: "是否加急",
      required: false,
      visible: showSpan.value,
      as: "switch",
      options: {
        activeValue: 1,
        inactiveValue: 0,
      }
    },
    {
      prop: "clinicalDiagnosis",
      label: "检查技师",
      required: false,
      as: "select",
      visible: showSpan.value,
      options: {
        render: "doctor-table",
        //@ts-ignore
        loadMethod: () => $api.user.listDoctorAsOptions({ officeId: editingObj.value?.applyingOfficeId }),
      }
    },
  ];

  const editProps: FormProps = {
    model: editingObj.value,
    items: formItems.filter(i => i.visible),
    columns: 1,
  };

  return editProps;
});
//展开、收起 按钮点击事件
const isShowBtnClick = () => {
  showSpan.value = !showSpan.value
  isShowIcon.value = showSpan.value ? "ArrowUp" : "ArrowDown";
};

//查询按钮点击事件
const queryBtnClick = () => {
  emit("handleQuery", editingObj.value);
};

//重置登记按钮点击事件
const resetBtnClick = () => {
  editingObj.value = {};
  emit("handleQuery", editingObj.value);
};


watch(
  () => props.selectRegistration,
  (item) => {
    if (item && item.id) {
      editingObj.value = item;
    }
  },
  {
    immediate: true,
  }
);
</script>

<style lang="less" scoped>
.registration-query-form {
  height: 100%;
  overflow-y: auto;

  :deep(.el-form-item) {
    margin-bottom: 5px;
  }
}
</style>
